package com.nxk.modules.content.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nxk.modules.content.dao.ConCaseDao;
import com.nxk.modules.content.entity.ConCase;
import com.nxk.modules.content.service.ConCaseService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ConCaseServiceImpl extends ServiceImpl<ConCaseDao, ConCase> implements ConCaseService {
    
    
   @Override
   @Transactional(readOnly = false)
    public boolean save(ConCase conCase) {
        if (StringUtils.isNotBlank(conCase.getId())) {
            return super.updateById(conCase);
        } else {
            return super.save(conCase);
        }
    }

    @Override
    public IPage<ConCase> page(ConCase conCase) {
        Page<ConCase> page = new Page<ConCase>(conCase.getPageNo(), conCase.getPageSize());
        QueryWrapper<ConCase> queryWrapper = new QueryWrapper<ConCase>();
        if (StringUtils.isNotBlank(conCase.getCaseTitle())) {
            queryWrapper.lambda().like(ConCase::getCaseTitle, conCase.getCaseTitle());
        }
        queryWrapper.orderByAsc("sort").in("status", 1, 2);
        IPage<ConCase> result = super.page(page, queryWrapper);
        return result;

    }

    @Override
    @Transactional(readOnly = false)
    public boolean deleteById(String id) {
        return super.removeById(id);
    }

}
